﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat</title>
</head>
<body>
    <canvas id="mycanvas" width="1000" height="700" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvas = document.getElementById("mycanvas"); //绘图区域
        let gPaint = new FCPaint(); //绘图对象
        gPaint.canvas = canvas;
        scaleCanvas(gPaint);
        //判断是否移动端
        gPaint.isMobile = isMobileMode();
        if (gPaint.isMobile) {
            gPaint.scaleFactorX = 2.5;
            gPaint.scaleFactorY = 2.5;
        }
        addDefaultEvent(canvas, gPaint);
        class MyView extends FCView {
            constructor() {
                super();
            }
        };

        let backView  = new FCView();
        backView.dock = "fill";
        backView.backColor = "rgb(255,255,255)";
        addView(backView, gPaint);

        let myView = new MyView(); //我的视图
        //添加到框架
        addViewToParent(myView, backView);
        //设置位置
        myView.location = new FCPoint(100, 100);
        //设置大小
        myView.size = new FCSize(200, 200);
        myView.backColor = "rgb(255,0,0)";
        myView.borderColor = "rgb(0,0,0)";
        myView.allowDrag = true;
        myView.allowResize = true;
        myView.viewName = "myView";
        updateViewDefault(gPaint.views);
        invalidate(gPaint);

        function callAPI(cmd) {
            if (typeof (facecat) != 'undefined') {
                return facecat.callFaceCat(cmd);
            } else {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", "http://127.0.0.1:9962?" + cmd, false);
                xmlhttp.send(null);
                return xmlhttp.responseText;
            }
        }

        /*
        * 点击方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        * clicks:点击次数
        */
        gPaint.onClick = function (view, firstTouch, firstPoint, secondTouch, secondPoint, clicks) {
            onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks);
            if (view.viewName == "myView") {
                callAPI("func=fcscript&funcname=openNewTab('ChangeTheme');");
            }
        };

        /*
        * 重置大小
        */
        let resizeAll = function () {
            canvas.width = document.documentElement.clientWidth;
            canvas.height = document.documentElement.clientHeight;
            scaleCanvas(gPaint);
            updateViewDefault(gPaint.views);
            invalidate(gPaint);

        };


        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };

        updateViewDefault(gPaint.views);
        //刷新界面
        invalidate(gPaint);
    </script>
</body>
</html>
